#ifndef RTE_KT1260B_SSD1322_IO_HZ_H
#define RTE_KT1260B_SSD1322_IO_HZ_H


#include <rtos.h>
#include "ESP8266_SSD1322.h"

#define OLED_CMD  0    //写命令
#define OLED_DATA 1    //写数据

class ssd1322_io_hz : public ESP8266_SSD1322 {
public:
    ssd1322_io_hz(uint8_t scl, uint8_t sda, uint8_t cs, uint8_t dc, uint8_t zk_cs, uint8_t zk_sda);

    ~ssd1322_io_hz() override = default;

    void ssd1322_command(uint8_t c) override;

    void ssd1322_data(uint8_t c) override;

    void ssd1322_dataBytes(uint8_t *buf, uint32_t size) override;

    void Set_Column_Address(unsigned char a, unsigned char b);


    void Set_Row_Address(unsigned char a, unsigned char b);

    void Set_Write_RAM();

    void Set_Read_RAM();

    /****送指令到字库IC***/
    void ZK_command(unsigned char data) const;

    /****从字库IC中取汉字或字符数据（1个字节）***/
    unsigned char get_data_from_ROM() const;

    /*从相关地址（AddrHigh：地址高字节,AddrMid：地址中字节,AddrLow：地址低字节）中连续读出DataLen个字节的数据到 pBuff的地址*/
    /*连续读取*/
    void get_n_bytes_data_from_ROM(unsigned char AddrHigh, unsigned char AddrMid, unsigned char AddrLow,
                                   unsigned char *pBuff, unsigned char DataLen) const;


    //***************************************************************
    //  显示12*12 15*16 24*24 32*32 GB2312点阵汉字 2015-11晶奥测试通过
    //   zk_num：汉字 库中的类型  GB_1212 1616 2424 3232
    //   x: Start Column  开始列
    //   y: Start Row   开始行 0~63
    //***************************************************************
    void Display_GB2312(unsigned char zk_num, unsigned int x, u8 y);


    //***************************************************************
    //  显示6*12 8*16 12*24 16*32 GB2312点阵ASCII 2015-11晶奥测试通过
    //zk_num定义： 字库的标示符 1: 6X12 点国标扩展字符,2:8X16 点国标扩展字符,3:8X16 点国标扩展特殊字符, 4:12X24 点国标扩展字符, 5:16X32 点国标扩展字符
    //   x: Start Column  开始列 范围 0~（256-16）
    //   y: Start Row   开始行 0~63
    //***************************************************************
    void Display_GBasc(unsigned char zk_num, unsigned int x, u8 y);


    //***************************************************************
    //* @brief
    //  显示 ASCII 2015-11晶奥测试通过
    //zk_num定义：1:5x7 ASCII,2:7x8 ASCII, 3:6x12 ASCII, 4:8x16 ASCII,	5: 12x24 ASCII,6:16x32 ASCII
    //   x: Start Column  开始列
    //   y: Start Row   开始行 0~63
    //***************************************************************
    void Display_Asc(unsigned char zk_num, unsigned int x, u8 y);

    /**************************************
  数据转换程序：将2位分成1个字节存入显存，由于1个seg表示4个列所以要同时写2个字节即4个像素
  uchar DATA：取模来的字模数据
****************************************/
    void Con_4_byte(unsigned char DATA);

    void begin(uint8_t i2caddr = SSD1322_I2C_ADDRESS, bool reset = true) override;

    int drawString(char *string, int16_t poX, int16_t poY, int size) override;

    int drawCentreString(char *string, int16_t dX, int16_t poY, int size) override;

    int drawHz1(const char *string, int poX, u8 poY, int size);

    int drawHz2(const char *string, int poX, u8 poY, int size);

    int drawAsc(char str, int poX, u8 poY, int size);

    int drawChar(char c, int16_t x, int16_t y, int size) override;

    void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
                  uint16_t bg, uint8_t size_x, uint8_t size_y) override;

private:
    uint8_t zk_cs = -1;
    uint8_t zk_sda = -1;
    u8 Shift = 0x1c;
    std::array<unsigned char, 128> FontBuf;//字库缓存
};


#endif //RTE_KT1260B_SSD1322_IO_HZ_H
